#include "CheckBox.h"

CheckBox::CheckBox(const std::string& txt, int x, int y) : highlighted(false), toggled(false)
{
    checkBox.SetPosition(x , y);
    checkBox.SetSize(sf::Vector2f(35, 35));
    checkBox.SetOutlineThickness(3);
    text.SetFont(font);
    text.SetString(txt);
    text.SetCharacterSize(23);
    text.SetPosition(x + 50 , y);
}

bool CheckBox::isClicked(float x, float y)
{
    sf::FloatRect rect(checkBox.GetGlobalBounds());
    if(rect.Contains(x, y))
    {
        sf::Sound* sound = new sf::Sound(rm->getSoundBuffer("click.ogg"));
        sound->Play();
        toggled = !toggled;
        return true;
    }
    return false;
}

void CheckBox::checkHL(float x, float y)
{
    sf::FloatRect rect(checkBox.GetGlobalBounds());
    if(rect.Contains(x, y))
        highlighted = true;
    else
        highlighted = false;
}

void CheckBox::draw(sf::RenderWindow* Window)
{
    Window->Draw(checkBox);
    if(highlighted)
        checkBox.SetOutlineColor(sf::Color::Yellow);
    else
        checkBox.SetOutlineColor(sf::Color::White);

    if(toggled)
        checkBox.SetFillColor(sf::Color::Green);
    else
        checkBox.SetFillColor(sf::Color::Red);

    Window->Draw(text);
}

